//Created: 4.20.22
//Updated: 1.04.23
//Cadence Willse

//Figure 1
use "County_Org_Analysis.dta", replace
preserve
collapse (sum) totrev org, by(year)
gen rev_mill = totrev/1000000
graph twoway (line rev_mill year) (line org year), ylabel(, angle(horizontal))
twoway (line rev_mill year, c(l) yaxis(1)) (line org year, c(l) yaxis(2)) 
list
restore
// Revenue growth: 278.2294-76.66395/76.66395
// Organizations growth: 455-158 /158

//Figure 2
use "County_Org.dta", replace
keep if year == 2015
drop stcofips stcofips state_fips county id
gen county = county_id
gen id = county_id
rename id countyfips
maptile_install using "http://files.michaelstepner.com/geo_county2010.zip"
maptile org, geo(county2010)

tab year if org>=1
tab year if org==0 // In 2015, at least 10.3% of counties have one or more large support nonprofit 

//Analysis and Variable Transformation
use "County_Org_Analysis.dta", replace
gen minority_pct = ((totalpop-white)/totalpop)*100
gen dem_pct = partisan_index_dem*100
gen rep_pct = partisan_index_rep*100


gen ln_minority = log(minority_pct)
gen ln_land = log(Pct_Protected)
gen ln_pov = log(Pov_FullPopPct)
gen ln_college = log(BA_pct)
gen ln_income = log(MHHInc)
gen ln_dem = log(dem_pct)
gen ln_rep = log(rep_pct)

//gen rural urban continuum code dummies
// https://www.ers.usda.gov/data-products/rural-urban-continuum-codes/documentation/
rename RuralurbanContinuumCode Rural_Urban
gen metro = 0
replace metro = 1 if Rural_Urban==1 | Rural_Urban==2 | Rural_Urban==3
gen recession = 0
replace recession = 1 if year>=2008
gen electionyr = 0
replace electionyr = 1 if year==2000 | year==2004 | year==2008 | year==2012 | year==2016
gen revpp = (totrev/totalpop)
replace revpp = . if revpp>7 //remove outliers

gen org_presence = 0
replace org_presence = 1 if org>0



//Table 1 
sum MHHInc Pov_FullPopPct minority_pct BA_pct e084parksrecdirectexp Pct_Protected metro dem_pct rep_pct  org revpp if org_p == 1 & year==2015
sum MHHInc Pov_FullPopPct minority_pct BA_pct e084parksrecdirectexp Pct_Protected metro dem_pct rep_pct if org_p == 0 & year==2015

preserve
keep if year == 2015
// TTEST
foreach var of varlist MHHInc Pov_FullPopPct BA_pct minority_pct metro dem_pct rep_pct Pct_Protected e084parksrecdirectexp {
di "`var'"
ttest `var', by(org_p)
}
restore

//Table 2, Model 1
logit org_presence ln_income ln_minority ln_college ln_dem ln_land metro ParksExp_change recession i.state, robust 


////LANDVOTE ANALYSIS

use  "County_Landvote.dta", replace

gen ln_minority = log(minority_pct)
gen ln_land = log(Pct_Protected)
gen ln_pov = log(Pov_FullPopPct)
gen ln_college = log(BA_pct)
gen ln_income = log(MHHInc)
gen ln_dem = log(dem_pct)
gen ln_rep = log(rep_pct)
gen org_dummy = 0
replace org_dummy = 1 if org>0
gen recession = 0
replace recession = 1 if year>=2008
gen electionyr = 0
replace electionyr = 1 if year==2000 | year==2004 | year==2008 | year==2012 | year==2016


//Appendix Table 1. Characteristics of Counties with and Without Conservation Ballot Initiatives
foreach var of varlist MHHInc Pov_FullPopPct BA_pct minority_pct metro dem_pct rep_pct Pct_Protected e084parksrecdirectexp org {
di "`var'"
ttest `var', by(_merge)
}
sum MHHInc Pov_FullPopPct BA_pct minority_pct metro dem_pct rep_pct Pct_Protected e084parksrecdirectexp org if _merge == 2 
sum MHHInc Pov_FullPopPct BA_pct minority_pct metro dem_pct rep_pct Pct_Protected e084parksrecdirectexp org if _merge == 3 

keep if _merge==3

//Table 3, Model 1
logistic passed org_d i.state_fips, robust

//Table 3, Model 2
logistic passed org_d ln_income ln_minority ln_college ln_dem ln_land metro ParksExp_change election bond i.state_fips, robust

//Table 3, Model 3 and 4
reg voteshare org_d i.state_fips, robust
reg voteshare org_d ln_income ln_minority ln_college ln_dem ln_land metro ParksExp_change election bond i.state_fips, robust
